<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:composite="http://java.sun.com/jsf/composite"
	xmlns:p="http://primefaces.org/ui">

<composite:interface>
	<composite:attribute name="myActionBean" required="true" />
	<composite:attribute name="myFormBean" required="true" />
	<composite:attribute name="showHistory" default="generateHistoricalValues" type="java.lang.String" />
	<composite:attribute name="property" default="value" type="java.lang.String" />
	<composite:attribute name="update" default="false" type="boolean" />

</composite:interface>
<composite:implementation>
	<h:outputStylesheet library="css" name="default.css" />
	<h:panelGrid columns="2">
		<h:outputText value="#{messages['defineUserGroup.name']} : " />
		<p:inputText value="#{cc.attrs.myFormBean.item.name}" />
	</h:panelGrid>

	<p:tabView value="#{cc.attrs.myFormBean.tabNames}" var="tabname">
		<p:tab title="#{tabname}">
			<p:dataTable var="value" value="#{cc.attrs.myActionBean.getValues(tabname)}">
				<p:column headerText="#{messages['variableDefination.variableName']}">
					<h:outputText value="#{value.variable.label}" />
				</p:column>
				<p:column headerText="#{messages['valueTemplate.value']}">
					<p:outputPanel rendered="#{value.variable.type eq 'String'}">
						<p:inputText value="#{value.core}" required="#{value.variable.required}" title="#{value.variable.description}" />
					</p:outputPanel>
					<p:outputPanel rendered="#{value.variable.type eq 'BigDecimal'}">
						<p:inputText value="#{value.core}" required="#{value.variable.required}">
							<f:convertNumber pattern="0.00" />
						</p:inputText>
					</p:outputPanel>
					<p:outputPanel rendered="#{value.variable.type eq 'Date'}">
						<p:calendar value="#{value.core}" pattern="dd/MM/yyyy" />
					</p:outputPanel>
					<p:outputPanel rendered="#{value.variable.type eq 'Enum'}">
						<p:selectOneMenu value="#{value.core}" label="Seçiniz">
							<f:selectItems value="#{value.variable.choiseSelectItems()}" />
						</p:selectOneMenu>
					</p:outputPanel>
					<p:outputPanel rendered="#{value.variable.type eq 'List'}">
						<p:dataTable value="#{value.core.listValues}" var="listValue" rowIndexVar="idx">
							<p:column headerText="Value">
								<p:inputText value="#{listValue.value}" />
							</p:column>
							<p:column>
								<f:facet name="header">
									<p:commandLink action="#{value.core.addValue()}" update=":myForm">
										<p:graphicImage value="/images/add.png" />
									</p:commandLink>
								</f:facet>
								<p:commandLink action="#{value.core.removeValue}" update=":myForm">
									<f:setPropertyActionListener target="#{value.core.removeId}" value="#{idx}" />
									<p:graphicImage value="/images/remove.png" />
								</p:commandLink>
							</p:column>
						</p:dataTable>
					</p:outputPanel>
					<p:outputPanel rendered="#{value.variable.type eq 'DropDownList'}">
						<p:dataTable value="#{value.core.dropDownListVariableBeans}" var="listValue" rowIndexVar="idx">
							<p:column headerText="Value">
								<p:selectOneMenu value="#{listValue.value}">
									<f:selectItems value="#{value.variable.choiseSelectItems()}" />
								</p:selectOneMenu>
							</p:column>
							<p:column>
								<f:facet name="header">
									<p:commandLink action="#{value.core.addValue()}" update=":myForm">
										<p:graphicImage value="/images/add.png" />
									</p:commandLink>
								</f:facet>
								<p:commandLink action="#{value.core.removeValue}" update=":myForm">
									<f:setPropertyActionListener target="#{value.core.removeId}" value="#{idx}" />
									<p:graphicImage value="/images/remove.png" />
								</p:commandLink>
							</p:column>
						</p:dataTable>
					</p:outputPanel>
				</p:column>
				<p:column headerText="#{messages['foodDefination.since']}">
					<p:calendar value="#{value.since}" />
				</p:column>
				<p:column headerText="#{messages['foodDefination.till']}" rendered="#{cc.attrs.update}">
					<p:calendar value="#{value.till}" />
				</p:column>
				<p:column headerText="#{messages['valueTemplate.gecmis']}">
					<p:commandButton value="#{messages['valueTemplate.gecmisiGoster']}" oncomplete="dlg1.show();" update=":myForm"
						action="#{cc.attrs.myActionBean[cc.attrs.showHistory]}">
						<f:setPropertyActionListener target="#{cc.attrs.myFormBean[cc.attrs.property]}" value="#{value}" />
					</p:commandButton>
				</p:column>
			</p:dataTable>
		</p:tab>
	</p:tabView>
	<h:panelGrid columns="2">
		<p:commandButton value="#{messages['action.save']}" action="#{cc.attrs.myActionBean.save}" />
		<p:commandButton value="#{messages['action.cancel']}" action="#{cc.attrs.myActionBean.cancel}" />
	</h:panelGrid>

	<p:dialog widgetVar="dlg1" id="dialogPanel" header="#{messages['valueTemplate.tarihselDeger']}">
		<p:dataTable value="#{cc.attrs.myFormBean.selectedValues}" var="myValue" id="historyTable">
			<p:column headerText="#{messages['valueTemplate.value']}">
				<h:outputText value="#{myValue.core}" />
			</p:column>
			<p:column headerText="#{messages['foodDefination.since']}">
				<h:outputText value="#{myValue.since}" />
			</p:column>
			<p:column headerText="#{messages['foodDefination.till']}">
				<h:outputText value="#{myValue.till}" />
			</p:column>
		</p:dataTable>
	</p:dialog>
</composite:implementation>
</html>